package com.example.secondhandspringboot.controller;


import com.example.secondhandspringboot.constant.RedisConstant;
import com.example.secondhandspringboot.results.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/hotSearch")
@RequiredArgsConstructor
@CrossOrigin
@Slf4j
public class HotSearchController {

    private final StringRedisTemplate stringRedisTemplate;
    @GetMapping
    public Result<Set<String>> getHotSearchValue(){
        log.info("获取热榜");
        //获取排名前十搜索词
        Set<String> hotSearchValues = stringRedisTemplate.opsForZSet().reverseRange(RedisConstant.HOT_SEARCH, 0, -1);
        return Result.success(hotSearchValues);
    }
}
